package com.funtonow.jqdk.fkcs.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.alibaba.fastjson.JSON;
import com.funtonow.jqdk.R;
import com.funtonow.jqdk.base.BaseActivity;
import com.funtonow.jqdk.base.Constants;
import com.funtonow.jqdk.bean.HkInfoBean;
import com.funtonow.jqdk.bean.UserInfoBean;
import com.funtonow.jqdk.utils.HttpUtil;
import com.funtonow.jqdk.utils.LogUtil;
import com.funtonow.jqdk.utils.SPUtil;

import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import butterknife.BindView;
import okhttp3.Call;

import static com.funtonow.jqdk.base.UrlUtils.ED_JS;
import static com.funtonow.jqdk.base.UrlUtils.HK;

/**
 * @author Jiajien
 * @date 2019/8/23
 */
public class HkActivity extends BaseActivity {

    @BindView(R.id.tv_hk_num)
    TextView tvHknum;
    @BindView(R.id.tv_hk_xf)
    TextView tvHkXf;
    @BindView(R.id.tv_hk_xf_dk)
    TextView tvHkXfDk;
    @BindView(R.id.tv_hk_ze)
    TextView tvHkZe;
    @BindView(R.id.tv_hk_bank)
    TextView tvHkBank;

    private HkInfoBean hkInfoBean;

    @Override
    public int getLayoutRes() {
        return R.layout.activity_hk;
    }

    @Override
    public void onCreateActivity(@Nullable Bundle savedInstanceState) {
        initToolbar("还款");
        hkInfoBean = JSON.parseObject(getIntent().getStringExtra("hkInfo"), HkInfoBean.class);
        tvHkZe.setText(String.format(Locale.getDefault(), "%d.00", hkInfoBean.getZe()));
        tvHknum.setText(String.format("%s.00", hkInfoBean.getList().get(0).getBenjin()));
        tvHkXf.setText(String.format("%s.00", hkInfoBean.getList().get(0).getXifei()));
        tvHkXfDk.setText(String.format("%s.00", hkInfoBean.getRm().getXfdkj()));
        tvHkBank.setText(SPUtil.getUserInfo().getDetail().getBankNum());
        findViewById(R.id.btn_hk).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getHk();
            }
        });
    }

    private void getHk() {
        UserInfoBean userInfoBean = SPUtil.getUserInfo();
        Map<String, String> param = new HashMap<>();
        assert userInfoBean != null;
        param.put("appid", Constants.OWN_APP_ID);
        param.put("token", userInfoBean.getToken());
        param.put("openid", userInfoBean.getOpenid());
        param.put("orderid", hkInfoBean.getRm().getOrderid());
        HttpUtil.getInstance().postDataAsynToNet(HK, param, new HttpUtil.MyNetCall() {

            @Override
            public void success(Call call, String jsonString) throws IOException {
                LogUtil.i(jsonString + " ***********88  ");
                finish();
            }

            @Override
            public void failed(Call call, IOException e) {

            }
        });
    }

}
